package com.example.admin_oa.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.admin_oa.model.mapper.SysRoleMapper;
import com.example.admin_oa.model.service.SysRoleService;
import com.example.comment_oa.pojos.SysRole;
import com.example.comment_oa.pojos_vo.SysRoleVo;
import com.example.comment_oa.response.AjaxResponse;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("adminOa/role")
@CrossOrigin
public class RolesController {
    @Resource
    SysRoleMapper sysRoleMapper;
    @Resource
    SysRoleService service;

    @PostMapping("select")
    public AjaxResponse select(){
        QueryWrapper<SysRole> wrapper=new QueryWrapper<>();
        wrapper.orderByDesc("role_id");
        return AjaxResponse.success(sysRoleMapper.selectList(wrapper));
    }

    @PostMapping("add")
    public AjaxResponse add(@RequestBody SysRoleVo sysRole){
        System.out.println(sysRole.toString());
        return AjaxResponse.success(service.add(sysRole));
    }

    @PostMapping("down")
    public AjaxResponse down(@RequestBody SysRole sysRole){
        System.out.println(sysRole);
        return AjaxResponse.success(sysRoleMapper.updateById(sysRole));
    }
}
